home *** CD-ROM | disk | FTP | other *** search
- Path: news.uoregon.edu!newsadmin
- From: Pat O'Connor <pwoc@darkwing.uoregon.edu>
- Newsgroups: comp.lang.c++
- Subject: Newbie Template question
- Date: 10 Jan 1996 06:47:49 GMT
- Organization: University of Oregon
- Message-ID: <4cvnel$2cd@pith.uoregon.edu>
- NNTP-Posting-Host: darkwing.uoregon.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.4 sun4m)
- X-URL: news:comp.lang.c++
-
- I'm getting a linking error when using templates that I just don't understand.
- I have a linked-list class set up where I use a template for the data type.
- To debug it, I ran the following program:
-
- #include <iostream.h>
- #include "List.h"
-
- template <class T>
- void PrintList(List<T>& L)
- { for (L.First(); !L; ++L) cout << L() << endl; }
-
- main()
- {
- List<int> L;
- for (int i=1; i<5; i++) L.Insert(i);
- PrintList(L);
- return 0;
- }
-
- This program worked fine. The problem came when I made what I thought was an
- innocent change -- I figured that since I was only going to use "integer"
- Lists, there was no need for the template in PrintList. So, I replaced
- template <class T>
- void PrintList(List<T>& L)
- by the single line
- void PrintList(List<int>& L)
-
- When I compiled with this change, I started to get errors from the linker
- of the form
-
- Unresolved:
- List<int>::operator!(void)const
- List<int>::operator()(void) const
- List<int>::operator++(void)
-
- Why???????
- Thanks.
-
- Pat
-
-